﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkitPlus;
using System.Data;
using System.Data.SqlClient;
using System.Globalization;
using System.IO;
using System.Collections.Generic;



/// <summary>
/// Summary description for AccountsCurrencyFormat
/// </summary>
public class AccountSettings
{
    static string strRupesUrl = HttpContext.Current.Server.MapPath("~/Images/RupeeSymbol.png").ToString();
    public AccountSettings()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public static void setMinMaxDate(Control formControl)
    {
        if (HttpContext.Current.Session["FINYEAR"] != null)
        {
            int intCurrentYear = Convert.ToInt32(HttpContext.Current.Session["FINYEAR"].ToString());
            int intNextYear = intCurrentYear + 1;
            DateTime dtMinimumDate = Convert.ToDateTime("01/04/" + intCurrentYear.ToString());
            DateTime dtMaximumDate = Convert.ToDateTime("31/03/" + intNextYear.ToString());
            foreach (Control c in formControl.Controls)
            {
                if (c.GetType() == typeof(CalendarExtenderPlus))
                {
                    ((CalendarExtenderPlus)(c)).MinimumDate = dtMinimumDate;
                    ((CalendarExtenderPlus)(c)).MaximumDate = dtMaximumDate;
                    ((CalendarExtenderPlus)(c)).ShowToday = false;
                }
                if (c.HasControls())
                {
                    setMinMaxDate(c);
                }
            }
        }
    }
    public static void setMinDate(Control formControl)
    {
        Datautility DU = new Datautility();
        string strSql = "SELECT BOOKSFROMDATE FROM ACC_COMPANY";
        DataTable DTBooksDate = DU.getdata(strSql);
        if (DTBooksDate.Rows.Count > 0)
        {
            if (DTBooksDate.Rows[0]["BOOKSFROMDATE"].ToString() != string.Empty)
            {
                DateTime dtMinimumDate = Convert.ToDateTime(DTBooksDate.Rows[0]["BOOKSFROMDATE"].ToString());
                foreach (Control c in formControl.Controls)
                {
                    if (c.GetType() == typeof(CalendarExtenderPlus))
                    {
                        ((CalendarExtenderPlus)(c)).MinimumDate = dtMinimumDate;
                        ((CalendarExtenderPlus)(c)).ShowToday = false;

                    }
                    if (c.HasControls())
                    {
                        setMinDate(c);
                    }
                }
            }
        }
    }
    public static void SetDate( Control formcontrol)
    {
        Datautility DU = new Datautility();
        string strsql = "SELECT BOOKSFROMDATE FROM ACC_COMPANY";
        DataTable DTBookDate = DU.getdata(strsql);
        if (DTBookDate.Rows.Count > 0)
        {
            if (DTBookDate.Rows[0]["BOOKSFROMDATE"].ToString() != string.Empty)
            {
                DateTime dtMaximumDate = System.DateTime.Now;
                foreach (Control c in formcontrol.Controls)
                {
                    if (c.GetType() == typeof(CalendarExtenderPlus))
                    {
                        ((CalendarExtenderPlus)(c)).MaximumDate = dtMaximumDate;
                    }
                    if (c.HasControls())
                    {
                        SetDate(c);
                    }
                }
            }
        }
    }
    public string GetCurrency(double CurrencyValue)
    {
        string strReturnValue = CurrencyValue.ToString();
        if (CurrencyValue.ToString() != string.Empty)
        {
            if (HttpContext.Current.Session["LargeAmount"] != null)
            {
                
                string strDecimalPlace = "{0:0.";
                int intDecimalPlace = Convert.ToInt32(HttpContext.Current.Session["DecimalPlace"].ToString());
                for (int i = 1; i <= intDecimalPlace; i++)
                {
                    strDecimalPlace += "0";
                }
                strDecimalPlace += "}";
                if (HttpContext.Current.Session["LargeAmount"].ToString() == "1")
                {
                    strReturnValue = Convert.ToDouble(string.Format(strDecimalPlace, Math.Abs(CurrencyValue))).ToString("c", new CultureInfo("hi-IN")).Replace("रु", "");
                }
                else
                {
                    strReturnValue = Convert.ToDouble(string.Format(strDecimalPlace, Math.Abs(CurrencyValue))).ToString("c", new CultureInfo("en-GB")).Replace("£", "");
                }
                if (CurrencyValue < 0)
                {
                    if (HttpContext.Current.Session["Negative"].ToString() == "1")
                    {
                        strReturnValue = "(-)" + strReturnValue;
                    }
                    else
                    {
                        strReturnValue = "(" + strReturnValue + ")";
                    }
                }

            }

        }
        return strReturnValue;
    }

    public string GetCurrencyWithSymbol(double CurrencyValue)
    {
        string strReturnValue = CurrencyValue.ToString();
        if (CurrencyValue.ToString() != string.Empty)
        {
            if (HttpContext.Current.Session["LargeAmount"] != null)
            {         

                string strDecimalPlace = "{0:0.";
                int intDecimalPlace = Convert.ToInt32(HttpContext.Current.Session["DecimalPlace"].ToString());
                for (int i = 1; i <= intDecimalPlace; i++)
                {
                    strDecimalPlace += "0";
                }
                strDecimalPlace += "}";
                if (HttpContext.Current.Session["LargeAmount"].ToString() == "1")
                {
                    strReturnValue = Convert.ToDouble(string.Format(strDecimalPlace, Math.Abs(CurrencyValue))).ToString("c", new CultureInfo("hi-IN")).Replace("रु", "");
                }
                else
                {
                    strReturnValue = Convert.ToDouble(string.Format(strDecimalPlace, Math.Abs(CurrencyValue))).ToString("c", new CultureInfo("en-GB")).Replace("£", "");
                }
                if (CurrencyValue < 0)
                {
                    if (HttpContext.Current.Session["Negative"].ToString() == "1")
                    {
                        strReturnValue = "(-)" + strReturnValue;
                    }
                    else
                    {
                        strReturnValue = "(" + strReturnValue + ")";
                    }
                }
                if (HttpContext.Current.Session["CurrencySymbol"] != null)
                {
                    if (HttpContext.Current.Session["CurrencySymbol"].ToString() == "1")
                    {
                        strReturnValue = "$&nbsp;" + strReturnValue;
                    }
                    else if (HttpContext.Current.Session["CurrencySymbol"].ToString() == "2")
                    {
                        strReturnValue = "£&nbsp;" + strReturnValue;
                    }
                    else
                    {
                        strReturnValue = "<img height='9px' width='7px' src='" + strRupesUrl + "' />&nbsp;" + strReturnValue;
                    }
                }

            }

        }
        return strReturnValue;
    }
    public string GetCurrencySymbol()
    {
        string strCurrencySymbol = "Rs.";
        if (HttpContext.Current.Session["CurrencySymbol"] != null)
        {
            if (HttpContext.Current.Session["CurrencySymbol"].ToString() == "1")
            {
                strCurrencySymbol = "$";
            }
            else if (HttpContext.Current.Session["CurrencySymbol"].ToString() == "2")
            {
                strCurrencySymbol = "£";
            }
            else
            {
                strCurrencySymbol = "<img src='" + strRupesUrl + "' /> ";
            }
        }
        return strCurrencySymbol;
    }

}


